package com.aseo.business.hibernate;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.aseo.model.dao.Dao;
import com.aseo.model.entity.hibernate.Vehiculo;

@Service
public class VehiculoManager implements ManagerInterface<Vehiculo> {

	@Resource  
	private Dao dao;
	
	@Override
	public List<Vehiculo> getAll() {
		final List<Vehiculo> list = dao.find(Vehiculo.class);  
	    return list;
	}

	@Override
	public void persist(Vehiculo t) {
		dao.persist(t);
	}

	public List<Vehiculo> getAllActivos(){
		final List<Vehiculo> list = dao.find("SELECT vehiculo " +
                "FROM com.aseo.model.entity.hibernate.Vehiculo vehiculo " +
                "WHERE vehiculo.estado=1 ");
		return list;
	}
	
	public List<Vehiculo> getVehiculoByPlaca(String placa){
		final List<Vehiculo> list = dao.find("SELECT vehiculo " +
                "FROM com.aseo.model.entity.hibernate.Vehiculo vehiculo " +
                "WHERE vehiculo.placa='"+placa+"' AND vehiculo.estado=1" );
		
		return list;
	}
	
	public List<Vehiculo> getVehiculoByCodigo(String codigo){
		final List<Vehiculo> list = dao.find("SELECT vehiculo " +
                "FROM com.aseo.model.entity.hibernate.Vehiculo vehiculo " +
                "WHERE vehiculo.codigo='"+codigo+"' AND vehiculo.estado=1" );
		
		return list;
	}

}
